#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //1.先给按钮加上图片
    ui->pushButton_up->setIcon(QIcon(":/image/up.png"));//设置图标
    ui->pushButton_up->setIconSize(QSize(50,50));//设置图标大小
    ui->pushButton_down->setIcon(QIcon(":/image/down.png"));
     ui->pushButton_down->setIconSize(QSize(50,50));
    ui->pushButton_left->setIcon(QIcon(":/image/left.png"));
     ui->pushButton_left->setIconSize(QSize(50,50));
    ui->pushButton_right->setIcon(QIcon(":/image/right.png"));
     ui->pushButton_right->setIconSize(QSize(50,50));
    ui->pushButton_target->setIcon(QIcon(":/image/Naruto_cursor.png"));
     ui->pushButton_target->setIconSize(QSize(50,50));

     //设置快捷键-字母字符串
     ui->pushButton_up->setShortcut(QKeySequence("Ctrl+w"));//大小写都可以，支持多键位
     ui->pushButton_down->setShortcut(QKeySequence("s"));
     ui->pushButton_left->setShortcut(QKeySequence("a"));
     ui->pushButton_right->setShortcut(QKeySequence("d"));

     //设置快捷键-枚举
//     ui->pushButton_up->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_W));//也可以使用多个键位
//     ui->pushButton_down->setShortcut(QKeySequence(Qt::Key_S));
//     ui->pushButton_left->setShortcut(QKeySequence(Qt::Key_A));
//     ui->pushButton_right->setShortcut(QKeySequence(Qt::Key_D));

     //设置重复触发
     ui->pushButton_up->setAutoRepeat(true);
     ui->pushButton_down->setAutoRepeat(true);
     ui->pushButton_left->setAutoRepeat(true);
     ui->pushButton_right->setAutoRepeat(true);

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_up_clicked()
{
    QRect rec=ui->pushButton_target->geometry();//获取位置大小
    ui->pushButton_target->setGeometry(rec.x(),rec.y()-5,rec.width(),rec.height());//设置移动位置
}

void Widget::on_pushButton_down_clicked()
{

    QRect rec=ui->pushButton_target->geometry();//获取位置大小
    ui->pushButton_target->setGeometry(rec.x(),rec.y()+5,rec.width(),rec.height());//设置移动位置
}

void Widget::on_pushButton_left_clicked()
{

    QRect rec=ui->pushButton_target->geometry();//获取位置大小
    ui->pushButton_target->setGeometry(rec.x()-5,rec.y(),rec.width(),rec.height());//设置移动位置
}

void Widget::on_pushButton_right_clicked()
{

    QRect rec=ui->pushButton_target->geometry();//获取位置大小
    ui->pushButton_target->setGeometry(rec.x()+5,rec.y(),rec.width(),rec.height());//设置移动位置
}
